
(function () {
    /*
  * 页面公共参数
  */
    var o = {};

    /*
     * 给页面参数赋值
     */
    function setParam() {
        var result = $.extend(true, o, getUrlParamsToJson());

        return result;
    }

    function initPage() {
        $('#btn_submit').on('click', function () {
            submit();
        });
    }

    function submit() {
        var data = $('#frm').serializeObject();

        var noArr = [];

        //检查各个题目是否都已做并记下分数
        for (var i = 1; i <= 12; i++) {
            var val = data['t_' + i];

            if (!val) {
                noArr.push(i);
            }
        }

        //检查各个题目是否都已做
        if (noArr.length) {
            alert('您还有' + noArr.toString() + '题没做，请做完再提交。');

            return false;
        } else {
            var total = 0;

            for (var key in data) {
                if (data.hasOwnProperty(key)) {
                    var val = data[key];
                    
                    if (Number(val)) {
                        total += Number(val);
                    } else {
                        for (var i = 0; i < val.length; i++) {
                            total += Number(val[i]);
                        }
                    }
                }
            }

            $('#grade').text(total);

            if (total < 12) {   //禁止开户
                $('#result_container').show();
                $('#txt_alert').text('您的得分太低了~').show();
            } else {    ///允许开户
                $('#result_container').show();
                $('#txt_alert').show();
                $('.sub-btn').show();
            }
        }
    }

    $(function () {
        o = setParam();

        initPage();
    });
})();